package kr.hyunist.androidcomplete02saeildamil.ch26;

import kr.hyunist.androidcomplete02saeildamil.R;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class ProductListEx extends Activity {
	ProductDBHelper mHelper;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.productlistex);

		mHelper = new ProductDBHelper(this);
		Cursor cursor;
		SQLiteDatabase db = mHelper.getWritableDatabase();

		cursor = db.rawQuery("select * from product", null);
		startManagingCursor(cursor);

		SimpleCursorAdapter adapter = null;
		adapter = new SimpleCursorAdapter(this,
				android.R.layout.simple_list_item_2, cursor, new String[] {
						"name", "price" }, new int[] { android.R.id.text1,
						android.R.id.text2 });
		ListView list = (ListView) findViewById(R.id.productlistlist);
		list.setAdapter(adapter);
		
	}
}
